package org.utils;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class ActionUtils extends ActionSupport implements SessionAware {

	protected static final long serialVersionUID = 1L;
	protected Map<String, Object> session;
	protected HttpServletRequest request =  ServletActionContext.getRequest();
	protected HttpServletResponse response =  ServletActionContext.getResponse();
	protected JSONObject json = new JSONObject();
	protected JSONArray array = new JSONArray();
	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	protected void render(String content) {
		response.setContentType("application/json; charset=utf-8");
		try {
			response.getWriter().write(content);
			response.getWriter().flush();
			response.getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
